<?php

namespace App\Models;

use Illuminate\Database\Eloquent\SoftDeletes;

class Article extends Model
{
    use SoftDeletes;

    protected $table = 'articles';

    protected $fillable = [
        'title',
        'publish_time',
        'description',
        'content',
        'key',
    ];

    protected $casts = [
        'publish_time' => 'datetime',
    ];

    /**
     * 根据key获取文章
     *
     * @param string $key
     * @return Article|null
     */
    public static function findByKey(string $key)
    {
        return self::where('key', $key)->first();
    }

    /**
     * 获取用户协议
     *
     * @return Article|null
     */
    public static function getUserAgreement()
    {
        return self::findByKey('user-agreement');
    }

    /**
     * 获取隐私协议
     *
     * @return Article|null
     */
    public static function getPrivacyPolicy()
    {
        return self::findByKey('privacy-policy');
    }

    /**
     * 获取付费会员用户服务协议
     *
     * @return Article|null
     */
    public static function getVipServiceAgreement()
    {
        return self::findByKey('vip-service-agreement');
    }
}
